package com.huping.mapper;

import com.huping.pojo.Grade;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface GradeMapper {
    @Insert("insert into grade (student_id,homework_id)values (#{userid},#{homeworkId})")
    public int gradeInsert(String userid, Integer homeworkId);

    //    查看此学生此作业是否已存在
    @Select("select count(*) from grade where student_id=#{studentId} and homework_id = #{homeworkId}")
    public long checkGradeExist(Grade grade);

    @Select("select grade_id gradeId,student_id studentId,grade.homework_id homeworkId,content,grade.file,status,huping_start_time hupingStartTime,huping_end_time hupingEndTime,type, code,score_total scoreTotal,comment from grade , homework  where grade.homework_id=homework.homework_id and grade.homework_id=#{homeworkId} and student_id=#{userid}")
    public Map<String,Object> getGradeDetails(Integer homeworkId, String userid);

    @Update("update grade set content=#{content},status=#{status} where grade_id=#{gradeId}")
    public int updateGradeContent(Grade grade);

    @Select("select file from grade where grade_id=#{gradeId}")
    String getGradeFile(Integer gradeId);

    @Update("update grade set file=#{fileListStr} where grade_id=#{gradeId}")
    int updateGradeFile(Integer gradeId, String fileListStr);

    @Update("update grade set score_teacher=#{score},comment=#{comment} where homework_id=#{homeworkId} and student_id=#{studentId}")
    public int teacherUpdateStudentScore(Integer homeworkId, String studentId, Integer score,String comment);


    public Map<String, Object> getHupingStudentHomeworkByOrder(String userid, Integer homeworkId, Integer skip);

    public List<Map<String, Object>> getHupingStudentHomeworkByRank(String rankValue,String userid);
    @Update("update grade set numbers=numbers+1 where student_id=#{studentId} and homework_id=#{homeworkId}")
    public void updateNumbersInGrade(String numbers, String studentId, Integer homeworkId);

    @Select("select count(score_total)  from grade where homework_id=#{homeworkId} and score_total>=85  ")

    public int getGradeStatisticA(Integer homeworkId);

    @Select("select count(score_total)  from grade where homework_id=#{homeworkId} and score_total<85 and score_total>=70 ")
    public int getGradeStatisticB(Integer homeworkId);

    @Select("select count(score_total)  from grade where homework_id=#{homeworkId} and score_total<70 and score_total>=60 ")
    public int getGradeStatisticC(Integer homeworkId);

    @Select("select count(score_total)  from grade where homework_id=#{homeworkId} and score_total<60  ")
    public int getGradeStatisticD(Integer homeworkId);

    @Select("select count(status)  from grade where homework_id=#{homeworkId} and status = '0'  ")
    public int getGradeStatisticNotSubmit(Integer homeworkId);
    @Select("select count(status)  from grade where homework_id=#{homeworkId} and status = '1'  ")
    public int getGradeStatisticSubmit(Integer homeworkId);
    public List<Map<String,Object>>  getExcellentHomework(Integer homeworkId);

    @Update("update grade set excellent=#{excellent} where homework_id=#{homeworkId} and student_id=#{studentId}")
    public void updateExcellent(Integer homeworkId, String studentId,String excellent);


    public  List<Map<String,Object>> getNotSubmit(Integer homeworkId);

    public  Map<String,Object> getTotal(String userid,Integer homeworkId);

    @Select("select score_teacher from grade where student_id=#{userid} and homework_id=#{homeworkId}")
    public  Integer getStudentScoreTeacher(String userid,Integer homeworkId);

   @Update("update grade set score_total=#{scoreTotal} where student_id=#{userid} and homework_id=#{homeworkId}")
    public  void setScoreTotal(String userid,Integer homeworkId,Integer scoreTotal);
    @Update("update grade set score_huping=#{scoreHuping} where student_id=#{userid} and homework_id=#{homeworkId}")
    public  void setScoreHuping(String userid,Integer homeworkId,Integer scoreHuping);

    @Select("select count(*) from grade where score_teacher is null and homework_id=#{homeworkId} ")
    public  int CheckScoreTeacherNullExist(Integer homeworkId);

    public  List<Map<String,Object>> getAllScoreTeacher(Integer homeworkId);

    @Update("update grade set rank_teacher=#{rankValue}  where homework_id=#{homeworkId} and student_id=#{studentId} ")
    public void setRank(Integer homeworkId,String studentId,String rankValue);

    @Select("select student_id, content from grade where homework_id=#{homeworkId} and content IS NOT NULL")
    List<Map<String, String>> getAllContentByHomeworkId(Integer homeworkId);

    @Select("select student_id, code from grade where homework_id=#{homeworkId} and code IS NOT NULL")
    List<Map<String, String>> getAllCodeByHomeworkId(Integer homeworkId);
}
